package com.kaxicore.kaxi.serviceImpl;
import java.util.List;
import java.lang.Integer;

import com.kaxicore.kaxi.mapper.UserXmlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.kaxicore.kaxi.entity.User;
import com.kaxicore.kaxi.mapper.UserMapper;
import com.kaxicore.kaxi.service.UserService;

@Service // 这个注解应该加在具体的实现类上
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper mapper;

    @Autowired
    private UserXmlMapper userXmlMapper;

    @Override
    public List<User> geTestUsers() throws Exception {

        return mapper.geTestUsers();
    }

    @Override
    public User getUserById(Integer id) throws Exception {
        User user = userXmlMapper.findUserById(id);
        return user;
    }

    @Override
    public List<User> findAll() throws Exception {
        return userXmlMapper.findAll();
    }

    @Override
    public void updateTestUser(User user) throws Exception {
        mapper.updateTestUser(user);
    }

    @Override
    public Boolean register(User user) throws Exception {
        if (mapper.getUserByName(user.getUserName()) != null) {
            return false;
        }
        mapper.addTestUser(user);
        return true;
    }

    @Override
    public User login(String userName, String password) throws Exception {
        User user = mapper.getUserByName(userName);
        if (user == null) {
            return null;
        }
        if (!user.getPassword().equals(password)) {
            return null;
        }
        return user;
    }

    @Override
    public void deleteTestUser(Integer testUserNo) throws Exception {
        mapper.deleteTestUser(testUserNo);
    }
}
